<?php

namespace App\Controllers\Home;

use App\Controllers\Controller;
use App\Facades\Db;
use App\Utils\QRcode;
use App\Utils\RandNumImage;
use App\Utils\UploadFile;
use App\Logics\UploadsLogic;

class DataController extends Controller
{

    public function initProduct()
    {
        $res = Db::table('product')->find(3);
        //print_r($res);exit;
        $dataList = [];
        for($i=2; $i<18; $i++){
            $dataList[] = [
                'class_id' => $res['class_id'],
                'title' => $res['title'] . $i,
                'cover' => $res['cover'],
                'content' => $res['content'],
                'seo_title' => $res['seo_title'] . $i,
                'created_at' => now(),
                'updated_at' => now(),
            ];
        }
        //print_r($dataList);exit;
        Db::table('product')->batchInsert($dataList);
        //print_r($res);
    }

    public function initArticle() {
        $res = Db::table('article')->find(11);
        //print_r($res);exit;
        $dataList = [];
        for($i=2; $i<=6; $i++){
            $dataList[] = [
                'class_id' => $res['class_id'],
                'title' => $res['title'] . $i,
                'cover' => $res['cover'],
                'content' => $res['content'],
                'seo_title' => $res['seo_title'] . $i,
                'created_at' => now(),
                'updated_at' => now(),
            ];
        }
        //print_r($dataList);exit;
        Db::table('article')->batchInsert($dataList);
    }

    public function initFriendLink(){
        $templateContent = '            <div class="links_ul">  <a href="http://Www.KouMai.Com/" target="_blank">代理联盟</a> <a href="http://www.hainait.com/kuaisuhuoke.html" target="_blank">快速获客</a> <a href="http://www.WanWeiZhan.Com" target="_blank">万维站长网</a> <a href="http://www.zhiidc.com/" target="_blank">智慧云</a> <a href="http://www.5MoBan.Com" target="_blank">我的模板网</a> <a href="http://www.XianSuoKe.com" target="_blank">线索客</a> <a href="http://www.PBku.cn/" target="_blank">PbootCMS模板库</a> <a href="http://www.kuaimoban.com/" target="_blank">快模板</a> <a href="http://www.XinMuLu.Com" target="_blank">新目录导航</a> <a href="http://www.pcLz.com" target="_blank">撸站</a> <a href="http://www.mbzw.com" target="_blank">模板站网</a> <a href="http://www.zlwz.Com" target="_blank">助力网址</a> <a href="http://www.YunYunAn.Com" target="_blank">云云安</a> <a href="http://www.YunYouCms.com" target="_blank">YunYouCms</a> <a href="http://www.eNiceBox.Com" target="_blank">建站宝盒</a> <a href="http://www.pbma.cn" target="_blank">pb源码网</a> <a href="http://www.eYouAdmin.Com" target="_blank">易优模板</a> <a href="http://www.KouNian.Cn" target="_blank">蔻念</a> <a href="http://www.DaYunYou.com" target="_blank">大云优模板</a> <a href="http://www.cnymc.com/pbootcms/" target="_blank">PbootCMS模板</a> <a href="http://www.EcLong.com/" target="_blank">商龙PBootCMS模板</a> <a href="http://www.bajiezhan.com/" target="_blank">八戒站长模板网</a> <a href="http://www.PBmbk.com/" target="_blank">PB模板库</a> <a href="http://www.mobanqi.com/" target="_blank">模板齐</a> <a href="http://www.Elubaba.Com/" target="_blank">西部空间5折</a> <a href="http://www.PB6789.Com/" target="_blank">PB6789</a> <a href="http://www.pbootmoban.com/" target="_blank">Pboot模板网</a> <a href="http://www.PBquan.com/" target="_blank">Pb模板圈</a> <a href="http://www.PBxia.com/" target="_blank">Pb下载网</a> <a href="http://www.yuanmaqi.com/" target="_blank">源码齐</a> <a href="http://www.KaiFaTang.Com/" target="_blank">开发堂模板网</a> <a href="http://www.KuiHao.com/" target="_blank">魁好</a> <a href="http://www.XinYunZhan.com/" target="_blank">新云站</a> <a href="http://www.XueYiLu.com" target="_blank">学艺路</a> <a href="http://www.WanWeiZhan.com/" target="_blank">万维站</a> <a href="http://www.YuanMaQi.com/" target="_blank">源码齐</a> <a href="http://www.SuCaiQi.com" target="_blank">素材齐</a> <a href="http://Www.JianZhanCMS.Com/" target="_blank">建站CMS</a> <a href="http://www.PBmo.cn/" target="_blank">pb模板网</a> <a href="http://www.HaiNaBa.Com/" target="_blank">海纳吧</a> <a href="http://www.yiqida.com/tpl/" target="_blank">多城市分站</a> <a href="http://www.pbzhan.com" target="_blank">pb站长网</a> <a href="http://www.pbyuan.com" target="_blank">pb源码网</a> <a href="http://www.pbadmin.cn" target="_blank">pb站长网</a> <a href="http://www.pbqi.cn" target="_blank">pb模板代理网</a> <a href="http://www.pb5678.com" target="_blank">pb模板网代理</a> <a href="http://www.pbmbb.com" target="_blank">pb模板宝</a> <a href="http://www.pbmbx.com" target="_blank">pb模板下载网</a> <a href="http://www.pbmby.com" target="_blank">pb模板园</a> <a href="http://www.btmb.cn" target="_blank">比特模板网</a> </div>';
        $count = preg_match_all("/\<a href\=\"(.*?)\"(.*?)\>(.*?)<\/a>/i", $templateContent, $array);
        $dataList = [];
        for ($i=0; $i<$count; $i++){
            $dataList[] = [
                'title' => $array[3][$i],
                'url' => $array[1][$i],
                'created_at' => now(),
                'updated_at' => now(),
            ];
        }
        //print_r($dataList);
        Db::table('link')->batchInsert($dataList);
        exit;

    }

}